//
//  MessageHUD.m
//  DSYWangyi
//
//  Created by dllo on 16/3/11.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "DSYMessageHUD.h"
#import <MBProgressHUD.h>
#import <UIKit/UIKit.h>


@interface DSYMessageHUD ()


@end

@implementation DSYMessageHUD


- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

+ (void)showAddToView:(UIView *)view withMessage:(NSString *)message animated:(BOOL)animated
{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:animated];
    hud.labelText = NSLocalizedString(message, @"hud title");
    hud.mode = MBProgressHUDModeText;
    // 中心显示
    hud.xOffset = 0;
    hud.yOffset = 0;
    // 显示的描述后消失
//    [hud hideAnimated:YES afterDelay:2.f];
    [NSTimer scheduledTimerWithTimeInterval:1.5f target:self selector:@selector(hiddenHHHUD:) userInfo:hud repeats:NO];
}

+ (void)showAddToView:(UIView *)view withCustomView:(UIView *)customView showMessage:(NSString *)message animated:(BOOL)animated
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:animated];
    hud.mode = MBProgressHUDModeCustomView;
    hud.customView = customView;
    hud.labelText = NSLocalizedString(message, @"hud title");
    [NSTimer scheduledTimerWithTimeInterval:1.5f target:self selector:@selector(hiddenHHHUD:) userInfo:hud repeats:NO];
}

+ (void)hiddenHHHUD:(NSTimer *)timer {
    MBProgressHUD *hud = (MBProgressHUD *)(timer.userInfo);
    [hud hide:YES];
}


+ (UIImage *)imageWithColor:(UIColor *)color {
    
    // 描述矩形
    CGRect rect = CGRectMake(0, 0, 1, 1);
    // 开启位图上下文
    UIGraphicsBeginImageContext(rect.size);
    // 获取位图上下文
    CGContextRef context = UIGraphicsGetCurrentContext();
    // 使用color演示填充上下文
    CGContextSetFillColorWithColor(context, [color CGColor]);
    // 渲染上下文
    CGContextFillRect(context, rect);
    // 从上下文中获取图片
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    // 结束上下文
    UIGraphicsEndImageContext();
    
    return theImage;
}

@end
